using UnityEngine;

namespace CinemaDirector
{
	[CutsceneItem("Tween", "Count")]
	public class GGTweenCount : CinemaGlobalAction
	{
		public UILabel widget;

		public int from;

		public int to;

		public Interpolate.EaseType easeType;

		protected string cachedProperty;

		public void SetProperty(int val)
		{
			widget.text = val.ToString();
			widget.MarkAsChanged();
		}

		public void SetProperty(string text)
		{
			widget.text = text;
		}

		public string GetProperty()
		{
			return widget.text;
		}

		public int GetFrom()
		{
			return from;
		}

		public int GetTo()
		{
			return to;
		}

		public override void Trigger()
		{
			SetProperty(GetFrom());
		}

		public override void Initialize()
		{
			cachedProperty = GetProperty();
		}

		public override void Stop()
		{
			if (!Application.isPlaying)
			{
				SetProperty(cachedProperty);
			}
		}

		public override void ReverseTrigger()
		{
			End();
		}

		public override void End()
		{
			SetProperty(GetTo());
		}

		public override void ReverseEnd()
		{
			Trigger();
		}

		public override void UpdateTime(float time, float deltaTime)
		{
			Interpolate.Function function = Interpolate.Ease(easeType);
			float num = GetFrom();
			float num2 = GetTo();
			float f = function(num, num2 - num, time, Mathf.Max(0.01f, base.Duration));
			int property = Mathf.RoundToInt(f);
			SetProperty(property);
		}

		public override void SetTime(float time, float deltaTime)
		{
			if (!(time < 0f) && !(time > base.Duration))
			{
				UpdateTime(time, deltaTime);
			}
		}
	}
}
